package com.zw.admin.server.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.zw.admin.server.model.PGoods;

@Mapper
public interface PGoodsDao {

    @Select("select * from p_goods t where t.id = #{id}")
    PGoods getById(Long id);

    @Delete("delete from p_goods where id = #{id}")
    int delete(Long id);

    int update(PGoods pGoods);
    
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into p_goods(item_no, sku, goods_name, goods_type, brand, specific, place, property, pre_buy_cost, price, unit, is_sale, createTime, updateTime) values(#{itemNo}, #{sku}, #{goodsName}, #{goodsType}, #{brand}, #{specific}, #{place}, #{property}, #{preBuyCost}, #{price}, #{unit}, #{isSale}, #{createTime}, #{updateTime})")
    int save(PGoods pGoods);
    
    int insert(PGoods pGoods);
    
    int count(@Param("params") Map<String, Object> params);

    List<PGoods> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    @Select("select * from p_goods t where t.sku = #{sku}")
    PGoods getBySku(String sku);
    
    @Select("select * from p_goods t where t.item_no = #{itemNo}")
    PGoods getByItemNo(String itemNo);
    
    List<PGoods> listBySku(@Param("skuList") List<String> skuList);
}
